package com.spic.business.plan.team.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.spic.common.security.service.TokenService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import com.spic.business.plan.team.domain.PlanUser;
import com.spic.business.plan.team.service.IPlanUserService;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.page.TableDataInfo;

/**
 * 应急人员Controller
 * 
 * @author spic
 * @date 2021-11-10
 */
@RestController
@RequestMapping("/plan/planUser")
public class PlanUserController extends BaseController
{
    @Autowired
    private IPlanUserService planUserService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询应急人员列表
     */
    @PreAuthorize(hasPermi = "business/plan:planUser:list")
    @GetMapping("/list")
    public TableDataInfo list(PlanUser planUser) throws Exception {
        startPage();
        List<PlanUser> list = planUserService.selectPlanUserList(planUser);

        return getDataTable(list);
    }

    /**
     * 导出应急人员列表
     */
    @PreAuthorize(hasPermi = "business/plan:planUser:export")
    @Log(title = "应急人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlanUser planUser) throws Exception
    {
        List<PlanUser> list = planUserService.selectPlanUserList(planUser);
        ExcelUtil<PlanUser> util = new ExcelUtil<PlanUser>(PlanUser.class);
        util.exportExcel(response, list, "应急人员数据");
    }

    /**
     * 获取应急人员详细信息
     */
    @PreAuthorize(hasPermi = "business/plan:planUser:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(planUserService.selectPlanUserById(id));
    }

    /**
     * 新增应急人员
     */
    @PreAuthorize(hasPermi = "business/plan:planUser:add")
    @Log(title = "应急人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody PlanUser planUser)
    {
        return toAjax(planUserService.insertPlanUser(planUser));
    }

    /**
     * 修改应急人员
     */
    @PreAuthorize(hasPermi = "business/plan:planUser:edit")
    @Log(title = "应急人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody PlanUser planUser)
    {
        return toAjax(planUserService.updatePlanUser(planUser));
    }

    /**
     * 删除应急人员
     */
    @PreAuthorize(hasPermi = "business/plan:planUser:remove")
    @Log(title = "应急人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(planUserService.deletePlanUserByIds(ids));
    }
}
